package org.example.struct.array;

/**
 * @author liyishan
 * @date 2023/12/7 09:27
 * @apiNote
 */

public class Test02108FirstPalindrome {

    public static String firstPalindrome(String[] words) {
        int n = words.length;
        for (int i = 0; i < n; i++) {
            if (isPalindrome(words[i])) {
                return words[i];
            }
        }
        return "";
    }

    private static boolean isPalindrome(String s) {
        int n = s.length();
        for (int i = 0; i < n / 2; i++) {
            if (s.charAt(i) != s.charAt(n - i - 1)) {
                return false;
            }
        }
        return true;
    }
}
